<?php
namespace Admin\Controller;
class ArcitleController extends BaceController {
    function arcitle_list() {

        
       if (!empty($_POST)) {
           //添加一级分类
            $name=$_POST['name'];
            if (mb_strlen($name)<1 || mb_strlen($name)>15) {
                $this->ajaxReturn(array('pass'=>0,'msg'=>'请输入合法的名!'));
            }
            $arcitle=M('Arcitle');
            $id=$_POST['id'];
            $data=array(
                'title'=>$name,
                'fid'=>$id
            );
           $re= $arcitle->data($data)->add();
           if ($re) {
               $this->ajaxReturn(array('pass'=>1,'msg'=>'操作成功!'));
           }
          
       }
      
       //查询一级分类
       $arcitleOb=D('Arcitle');
       $optionstr=$arcitleOb-> getArcitle();
       $this->assign("optionstr",$optionstr);
       //查询所有分类
      $arr= M('Arcitle')->where('fid=0')->select();
       $this->assign('arr',$arr);
        $this->display();

    }   
    //修改
    public function arcitle_save() {
        if ($_GET){
         $name=$_GET['name'];
         $id=$_GET['id'];
         $this->assign('id',$id);
         $this->assign("name",$name);
        }
         if ($_POST) {
             $name=$_POST['name'];
             if(mb_strlen($name)<1 ||mb_strlen($name)>15) {
                 $this->ajaxReturn(array('pass'=>0,'msg'=>'请输入合法的名称!'));
             }
                 $id=$_POST['id'];
                 $data=array(
                   'title'=>$name,  
                 );
                 $re=M('Arcitle')->where("id=$id")->data($data)->save();
                 if ($re) {
                  $this->ajaxReturn(array('pass'=>1,'msg'=>'操作成功!'));   
                 }
         }
         
         $this->display();
    }
    //删除
    public function arcitle_delete() {
        $id=$_POST['id'];
        $re=M('Arcitle')->where("id=$id")->delete();
        if ($re) {
            $this->ajaxReturn(array('pass'=>1,'msg'=>'已删除'));
        }
    }
    //显示一级分类的子类
    function arcitle_getson() {
        
/*         $arcitle=M('Arcitle');
        $fid=$_GET['fid'];
        $num=$_GET['num'];
        $arr=$arcitle->where("fid=$fid")->select();
        $html="";
        $strGang=str_repeat("--",$num);//把--重复指定的次数
        $num++;
        foreach ($arr as $v) {
            $html.="
           <tr class=\"text-c\" id=\"tr_{$v['id']}\">
           <td><input type=\"checkbox\"></td>
          <td>{$v['id']}</td>
          <td>1</td>
          <td class=\"text-l\"><a href=\"javascripe:getSon({$v['id']},1)\">{$strGang}{$v['title']}</a></td>
          <td class=\"f-14\">
	          <a title=\"编辑\" href=\"javascript:;\" data-id=\"{$v['id']}\" data-name=\"{$v['title']}\" style=\"text-decoration:none\" class=\"save\"><i class=\"icon-edit\"></i></a> 
	          <a title=\"删除\" href=\"javascript:;\"  data-id=\"{$v['id']}\"  style=\"text-decoration:none\" class=\"delete\"><i class=\"icon-trash\"></i></a>
          </td>
           </tr>
                ";
        }
        var_dump($html);
   $this->assign("html",$html); */
    }

}